package com.gthncz;

import java.util.Scanner;

public class RangePanlinon {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        if (M < N || N < 0) {
            System.out.printf("0");
            return;
        }
        int res = 0;
        for(int i=N; i<=M; ++i){
            if (check(i)) ++res;
        }
        System.out.print(res);
    }

    private static boolean check(int num){
        StringBuilder builder = new StringBuilder();
        while(num > 0){
            builder.append(String.valueOf(num % 10));
            num /= 10;
        }
        String strNum = builder.toString();
        // 依次去掉数字
        for (int i=0; i<strNum.length(); ++i){
            String newNumStr = strNum.substring(0, i) + strNum.substring(i+1);
            newNumStr = rtrim(newNumStr);

            // 判断是否回文
            if (!(isRound(newNumStr))) continue;
            // 判断是否素数
            int newNum = 0;
            for (int j=0; j<newNumStr.length(); ++j){
                newNum = newNum*10 + (newNumStr.charAt(j)-'0');
            }
            if (isPusu(newNum)) return true;
        }
        return false;
    }

    private static String rtrim(String numStr){
        int i=numStr.length()-1;
        for(; i>=0 && numStr.charAt(i) == '0'; --i);
        return numStr.substring(0, i);
    }

    private static boolean isRound(String strNum){
        int i=0, j=strNum.length()-1;
        while (i<j && strNum.charAt(j) == '0') --j;
        while (i<j && strNum.charAt(i) == strNum.charAt(j)){
            ++i; --j;
        }
        return i>=j;
    }

    private static boolean isPusu(int num){
        for (int i=2; 2*i<num; ++i){
            if (num % i == 0) return false;
        }
        return true;
    }

}
